package com.stone.framework.batch.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.stone.framework.batch.entity.CaseAssign;
import com.stone.framework.batch.entity.CaseInfo;
import com.stone.framework.batch.entity.CaseState;
import com.stone.framework.batch.entity.Team;
import com.stone.framework.batch.model.CaseAllocBO;

public abstract class GenericCaseService extends AbstractCaseService {

    @Autowired
    private JdbcBatchService jdbcBatchService;

    private static final String QUERY_CASE_INFO =
        "SELECT * FROM st_case_info sci WHERE sci.org_code = :orgCode AND sci.project_code = :projectCode AND sci.event_code = :eventCode AND sci.batch_code = :batchCode AND sci.case_nbr = :caseNbr";
    private static final String DELETE_CASE_INFO = "DELETE sci FROM st_case_info WHERE sci.id = :id";
    private static final String NEW_CASE_INFO = "";
    private static final String UPDATE_CASE_STATE = "";
    private static final String MERGE_CASE_STATE = "";
    private static final String CLOSE_CASE_ASSIGN = "";
    private static final String NEW_CASE_ASSIGN = "";

    @Override
    protected void batchUpdate(List<CaseInfo> closedCaseInfoList, List<CaseInfo> newCaseInfoList,
        List<CaseState> updateCaseStateList, List<CaseState> newCaseStateList, List<CaseAssign> closedCaseAssignList,
        List<CaseAssign> newCaseAssignList) {
        jdbcBatchService.batchExecute(DELETE_CASE_INFO, closedCaseInfoList);
        jdbcBatchService.batchExecute(NEW_CASE_INFO, newCaseInfoList);
        jdbcBatchService.batchExecute(UPDATE_CASE_STATE, updateCaseStateList);
        jdbcBatchService.batchExecute(MERGE_CASE_STATE, newCaseStateList);
        jdbcBatchService.batchExecute(CLOSE_CASE_ASSIGN, closedCaseAssignList);
        jdbcBatchService.batchExecute(NEW_CASE_ASSIGN, newCaseAssignList);

    }

    @Override
    protected void update(CaseInfo closedCaseInfo, CaseInfo newCaseInfo, CaseState updateCaseState,
        CaseState newCaseState, CaseAssign closedCaseAssign, CaseAssign newCaseAssign) {
        jdbcBatchService.execute(DELETE_CASE_INFO, closedCaseInfo);
        jdbcBatchService.execute(NEW_CASE_INFO, newCaseInfo);
        jdbcBatchService.execute(UPDATE_CASE_STATE, updateCaseState);
        jdbcBatchService.execute(MERGE_CASE_STATE, newCaseState);
        jdbcBatchService.execute(CLOSE_CASE_ASSIGN, closedCaseAssign);
        jdbcBatchService.execute(NEW_CASE_ASSIGN, newCaseAssign);

    }

    @Override
    public CaseInfo queryCurrCaseInfo(CaseAllocBO caseAddBo) {
        List<CaseInfo> list = jdbcBatchService.queryList(QUERY_CASE_INFO, caseAddBo, CaseInfo.class);
        return list.isEmpty() ? null : list.get(0);
    }

    @Override
    protected Team getTeam(String teamCode) {
        // TODO Auto-generated method stub
        return null;
    }

}
